package javbot.command;

import java.awt.AWTException;
import java.awt.event.MouseEvent;

public class CmdClick extends Command {

	final private int times;
	final private int interDelay;
	final private int postDelay = 5;
	
	public CmdClick(int times) throws AWTException {
		super();
		this.times = times;
		this.interDelay = 5;
	}
	
	public CmdClick(int times, int delay) throws AWTException {
		super();
		this.times = times;
		this.interDelay = delay;
	}	
	
	public void execute() {
		int times_cnt = times;
		while (times_cnt!=0) {
			robot.mousePress(MouseEvent.BUTTON1_MASK);
			robot.delay(interDelay);
			robot.mouseRelease(MouseEvent.BUTTON1_MASK);
			robot.delay(postDelay);
			times_cnt--;
		}
	}
	
	public String toString() {
		if (times==1) 
			return "Click Once";
		else if (times==2) 
			return "Click Twice";
		else 
			return "Click " + times + " times";
		
	}	
	
}
